- /* slcomult.cpp by K.Tsuru */
- // function ID = 902
- /**************************
- SLComplex class
- multiplication (*this)*z = (a + bi)*(c + di)
- **************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- #define UsesSimpleCLCLMult 0
- SLComplex& SLComplex::operator*=(const SLComplex& z) {
- #if !UsesSimpleCLCLMult // UsesSimpleCLCLMult 0
- if ( IsZero(902) ) return *this; // a = b= 0
- if ( z.IsZero(902) ) { // c = d = 0
- SetZero(); return *this;
- }
- //cout << "UsesSimpleCLCLMult = " << UsesSimpleCLCLMult << endl;
- // d = 0, (a+bi)*c
- if (z.im.Sign(903) == SNumber::ZERO) return (*this) *= z.re;
- // c = 0, (a+bi)*di = -b*d +(a*d)i
- if (z.re.Sign(903) == SNumber::ZERO) {
- const SLong r = -im * z.im;
- im = re * z.im;
- re = r;
- return *this;
- }
-
- // if(&x == &y) { // z * z can be speed-up by z = a + ib, z^2 = a^2-b^2 + 2iab
- if(*this == z) { // Overhead is very small comparing above.
- SLong temp(0.0); // (a+ai)^2 = 2a^2i
- if (re != im) temp = re * re - im * im;
- im = re * im; im *= 2; // = DsMult(im, 2); // change since version 2.192
- re = temp;
- return *this;
- } else {
- #define UseCLCLMult3Times 1 // since version 2.3
- #if !UseCLCLMult3Times // UseCLCLMult3Times 0
- // (a + bi)*(c + di) = a*c - b*d +(a*d + b*c)i
- const SLong temp = re * z.re - im * z.im;
- im = re * z.im + im * z.re;
- re = temp;
- #else // UseCLCLMult3Times 1
- /*******************************
- (a + bi)*(c + di) = a*c - b*d +(a*d + b*c)i
- = a*(c -d) + d*(a -b)+{b*(c+d) + d*(a -b)}i
- = (re + i*im)*(z.re + i*z.im)
- Let re = a, im = b, z.re = c, z.im = d, temp = d*(a -b).
- ***********************************/
- //cout << "UseCLCLMult3Times = " << UseCLCLMult3Times << endl;
- const SDouble temp = z.im * (re - im); // three times *operator()
- re = re * (z.re - z.im) + temp; // a*(c-d)+temp
- im = im * (z.re + z.im) + temp; // b*(c+d)+temp
- #endif // UseCLCLMult3Times end
- return *this;
- }
-
- #else // UsesSimpleCLCLMult 1
- if (z.im.Sign(902) == SNumber::ZERO) return (*this) *= z.re;
-
- const SLong temp = re * z.re - im * z.im;
- im = re * z.im + im * z.re;
- re = temp;
- return *this;
- #endif
- }
slcomult.cpp : last modifiled at 2016/08/04 15:24:08(2,162 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).